<template>
  <div>
    <div class="recycle-div">
      <el-button type="text" size="mini" @click="recycleCustomerTask"><i class="el-icon-refresh"> 回收任务</i></el-button>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'RecycleCustomerTask',
    data () {
      return {
      }
    },
    created() {
    },
    methods: {
      recycleCustomerTask() {
        if (this.$store.state.user.serviceId === '') {
          this.$message.error('未找到当前用户信息');
          return;
        }

        this.$confirm('确认回收 ' + this.$store.state.user.serviceName + ' 所有未完成任务？')
          .then(_ => {
            this.recycle(this.$store.state.user.serviceId);
          })
          .catch(_ => {});
      },
      async recycle(customerId) {
        let data = await this.$$put('/task/recycle/customer/' + customerId);
        if (this.checkResponse(data)) {
          this.$message.success('回收任务成功，回收用户数 ' + data.data.data);
          this.$parent.loadCustomerTaskList2();
        }
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
.recycle-div {
  margin: 5px;
  text-align: right
}
</style>
